package com.wpml.common.util;

import lombok.*;

/**
 * @description:
 * @author: wp
 * @date: 2019-09-02 10:43
 **/
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResultJson {

    public static final Integer SUCCESS = 200;
    public static final Integer ERROR = 500;
    public static final Integer FAIL = -1;
    public static final String SUCCESS_MSG = "操作成功";
    public static final String FAIL_MSG = "操作失败";
    public static final String ERROR_MSG = "系统异常";

    private int status;

    private String msg;

    private Object data;

    private Integer total;

    public ResultJson(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static ResultJson ok(String code, String msg) {

        return new ResultJson(SUCCESS, msg);
    }

    public static ResultJson ok() {
        return new ResultJson(SUCCESS, SUCCESS_MSG);
    }

    public static ResultJson ok(Object data) {
        return new ResultJson(SUCCESS, SUCCESS_MSG, data, null);
    }

    public static ResultJson ok(Object pageList, int total) {
        return new ResultJson(SUCCESS, SUCCESS_MSG, pageList, total);
    }

    public static ResultJson fail(String msg) {
        return new ResultJson(FAIL, msg);
    }

    public static ResultJson error(String msg) {
        return new ResultJson(ERROR, msg);
    }

    public static ResultJson error() {
        return new ResultJson(ERROR, ERROR_MSG);
    }
}
